Skip to content

Don't report "no value type specified in iterable type array&callable"#5565

Merged
staabm merged 14 commits intophpstan:2.1.xfrom
staabm:callable-array
Apr 29, 2026
Merged

Don't report "no value type specified in iterable type array&callable"#5565
staabm merged 14 commits intophpstan:2.1.xfrom
staabm:callable-array

Conversation

@staabm
Copy link
Copy Markdown
Contributor

@staabm staabm commented Apr 29, 2026

@phpstan-bot
Copy link
Copy Markdown
Collaborator

You've opened the pull request against the latest branch 2.2.x. PHPStan 2.2 is not going to be released for months. If your code is relevant on 2.1.x and you want it to be released sooner, please rebase your pull request and change its target to 2.1.x.

@staabm staabm changed the base branch from 2.2.x to 2.1.x April 29, 2026 06:28
@ondrejmirtes
Copy link
Copy Markdown
Member

Also we could improve IntersectionType getIterableKeyType and ValueType if the type is array and callable.

@VincentLanglet
Copy link
Copy Markdown
Contributor

Also we could improve IntersectionType getIterableKeyType and ValueType if the type is array and callable.

That's not enough, because it won't report
https://phpstan.org/r/c90e4fe4-2ce7-4be3-8529-ae517dd5c445

@VincentLanglet
Copy link
Copy Markdown
Contributor

closes phpstan/phpstan#14549

I opened the issue about the fact it doesn't report an error on the line

$this->call($task);

So the current state of this PR doesn't solve it @staabm

@ondrejmirtes
Copy link
Copy Markdown
Member

I'd be interested why the line isn't reported there, seems like deficiency of ConstantArrayType::accepts().

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Apr 29, 2026

That's not enough, because it won't report

@VincentLanglet running https://phpstan.org/r/c90e4fe4-2ce7-4be3-8529-ae517dd5c445 locally I get a error on line 13 (even on 2.1.x)

➜  phpstan-src git:(2.1.x) ✗ php bin/phpstan analyze foo.php --debug 
Note: Using configuration file /Users/staabm/workspace/phpstan-src/phpstan.neon.dist.
/Users/staabm/workspace/phpstan-src/foo.php
 ------ -------------------------------------------------------------------------------------------------------------------------- 
  Line   foo.php                                                                                                                   
 ------ -------------------------------------------------------------------------------------------------------------------------- 
  6      Class MondayMorning must be abstract or final.                                                                            
         🪪  phpstan.finalClass                                                                                                    
         at foo.php:6                                                                                                              
  8      Method MondayMorning::foo() has parameter $task with no value type specified in iterable type array.                      
         🪪  missingType.iterableValue                                                                                             
         💡  See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type                                
         at foo.php:8                                                                                                              
  11     Dumped type: array&callable(): mixed                                                                                      
         🪪  phpstan.dumpType (non-ignorable)                                                                                      
         at foo.php:11                                                                                                             
  13     Parameter #1 $task of method MondayMorning::call() expects array{string, string, string}, array&callable(): mixed given.  
         🪪  argument.type                                                                                                         
         at foo.php:13                                                                                                             
 ------ -------------------------------------------------------------------------------------------------------------------------- 

@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Apr 29, 2026

ok its weird. the error is visible on level 7,8,9 - but not on level 10

https://phpstan.org/r/ad329e91-8e3f-49b4-a30f-d4b3f562d6f6

Comment thread src/Type/IntersectionType.php Outdated
Comment thread src/Type/IntersectionType.php Outdated
@staabm
Copy link
Copy Markdown
Contributor Author

staabm commented Apr 29, 2026

@VincentLanglet I think we should merge the inference improvements here and investigate the missing error on level 10 separately

Comment thread src/Rules/MissingTypehintCheck.php Outdated
Comment on lines +76 to +78
if ($type->isCallable()->yes() && $type->isArray()->yes()) {
return $type;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three question:

  • Does it still report something like (array&callable(array): array) which should report the param/return type of the callable ?
  • Does the isArray()->yes() check needed ?
  • Should it be after the ConditionalType in case of some conditionalType which is a callable ?

Copy link
Copy Markdown
Contributor Author

@staabm staabm Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Does it still report something like (array&callable(array): array) which should report the param/return type of the callable ?

while I feel such a type will be pretty rare, fixing it was easy enough

  • Does the isArray()->yes() check needed ?

I think so. we explicitly check this combination in more places.

  • Should it be after the ConditionalType in case of some conditionalType which is a callable ?

the fix for 1) added a explicit check for IntersectionType. that way it can not accidentally match ConditionalType anymore

@VincentLanglet
Copy link
Copy Markdown
Contributor

@VincentLanglet I think we should merge the inference improvements here and investigate the missing error on level 10 separately

I agree it's better to solve the missing error level on another PR

@VincentLanglet
Copy link
Copy Markdown
Contributor

Dunno if ondrej'll want to give a review on this

@staabm staabm merged commit 28f6ffe into phpstan:2.1.x Apr 29, 2026
652 of 657 checks passed
@staabm staabm deleted the callable-array branch April 29, 2026 21:24
bitwise-operators pushed a commit to bitwise-operators/phpstan-src that referenced this pull request Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

array&callable is not reported as a wrong param

4 participants